package org.codebase.spring.cloud.ribbonconsumer;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author:xiaozhichao
 * @date:2018/9/21
 */
@Service
public class HelloService {

    @Autowired
    RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "helloFallback")
    public String helloService() {
        long start = System.currentTimeMillis();
        String body = restTemplate.getForEntity("http://hello-service/hello", String.class).getBody();
        long end = System.currentTimeMillis();
        System.out.println("speed time : " + (end-start));
        return body;
    }

    public String helloFallback() {
        return "error";
    }
}


